package com.wuyou.sso.common.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Closeable;
import java.io.Flushable;

/**
 * CloseUtil
 *
 * @Date 2025/4/11 16:05
 * @Author 无忧
 */
public class CloseUtil {
    private static final Logger log = LoggerFactory.getLogger(CloseUtil.class);

    public CloseUtil() {
    }

    public static void close(Closeable... closeable) {
        close(true, closeable);
    }

    public static void close(boolean flush, Closeable... closeable) {
        if (null != closeable && closeable.length != 0) {
            Closeable[] var2 = closeable;
            int var3 = closeable.length;

            for(int var4 = 0; var4 < var3; ++var4) {
                Closeable close = var2[var4];
                if (null != close) {
                    try {
                        if (flush && close instanceof Flushable) {
                            Flushable flushable = (Flushable)close;
                            flushable.flush();
                        }

                        close.close();
                        close = null;
                    } catch (Exception var7) {
                        if (log.isDebugEnabled()) {
                            log.debug("There was a problem closing the stream, and the reason for the problem is {}", var7.getMessage());
                        }
                    }
                }
            }

        }
    }
}
